<!DOCTYPE html>
<!--
  Copyright 2016 Google Inc.

  Permission is hereby granted, free of charge, to any person obtaining a copy
  of this software and associated documentation files (the "Software"), to deal
  in the Software without restriction, including without limitation the rights
  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  copies of the Software, and to permit persons to whom the Software is
  furnished to do so, subject to the following conditions:

  The above copyright notice and this permission notice shall be included in
  all copies or substantial portions of the Software.

  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  THE SOFTWARE.
-->
<html>
  <head>
    <meta charset="utf-8">
    <title>Snackbar - Material Components Catalog</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="icon" type="image/png" href="/images/logo_components_color_2x_web_48dp.png">
    <link rel="stylesheet" href="/assets/snackbar.css">
    <script src="/ready.js"></script>
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto+Mono">
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500">
    <link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
    <style>
      /* initialize it off screen. */
      .loading .example .mdc-snackbar { transform: translateY(200%); }

      /* Override style for hero example. */
      .hero .mdc-snackbar {
        position: relative;
        left: auto;
      }
      .hero .mdc-snackbar--active {
        transform: none;
      }

      .field {
        padding-top: 8px;
        padding-bottom: 8px;
      }

      .demo-activate-button {
        margin-top: 14px;
      }

    </style>
  </head>
  <body class="mdc-typography loading">
    <header class="mdc-toolbar mdc-toolbar--fixed">
      <div class="mdc-toolbar__row">
        <section class="mdc-toolbar__section mdc-toolbar__section--align-start">
          <span class="catalog-back">
            <a href="/" class="mdc-toolbar__menu-icon"><i class="material-icons">&#xE5C4;</i></a>
          </span>
          <span class="mdc-toolbar__title catalog-title">Snackbar</span>
        </section>
      </div>
    </header>

    <main>
      <div class="mdc-toolbar-fixed-adjust"></div>
      <section class="hero">
        <div class="mdc-snackbar mdc-snackbar--active"
             aria-live="assertive"
             aria-atomic="true"
             aria-hidden="true">
          <div class="mdc-snackbar__text">Message sent</div>
          <div class="mdc-snackbar__action-wrapper">
            <button type="button" class="mdc-snackbar__action-button">Undo</button>
          </div>
        </div>
      </section>

      <section class="example">
        <h2 class="mdc-typography--headline6">Basic Example</h2>

        <div class="mdc-form-field">
          <div class="mdc-checkbox">
            <input type="checkbox" class="mdc-checkbox__native-control" id="multiline" aria-labelledby="multiline-label" />
            <div class="mdc-checkbox__background">
              <svg class="mdc-checkbox__checkmark" viewBox="0 0 24 24">
                <path class="mdc-checkbox__checkmark-path" fill="none" d="M1.73,12.91 8.1,19.28 22.79,4.59" />
              </svg>
              <div class="mdc-checkbox__mixedmark"></div>
            </div>
          </div>
          <label for="multiline" id="multiline-label">Multiline</label>
        </div>
        <br/>

        <div class="mdc-form-field">
          <div class="mdc-checkbox" id="action-on-bottom-checkbox">
            <input type="checkbox" class="mdc-checkbox__native-control" id="action-on-bottom" aria-labelledby="action-on-bottom-label" />
            <div class="mdc-checkbox__background">
                <svg class="mdc-checkbox__checkmark" viewBox="0 0 24 24">
                  <path class="mdc-checkbox__checkmark-path" fill="none"
                      d="M1.73,12.91 8.1,19.28 22.79,4.59"/>
                </svg>
              <div class="mdc-checkbox__mixedmark"></div>
            </div>
          </div>
          <label for="action-on-bottom" id="action-on-bottom-label">Action On Bottom</label>
        </div>
        <br/>

        <div class="mdc-form-field">
            <div class="mdc-checkbox">
              <input type="checkbox" checked class="mdc-checkbox__native-control" id="dismiss-on-action" aria-labelledby="dismiss-on-action-label" />
              <div class="mdc-checkbox__background">
                <svg class="mdc-checkbox__checkmark" viewBox="0 0 24 24">
                  <path class="mdc-checkbox__checkmark-path" fill="none"
                        d="M1.73,12.91 8.1,19.28 22.79,4.59"/>
                </svg>
              <div class="mdc-checkbox__mixedmark"></div>
            </div>
          </div>
          <label for="dismiss-on-action" id="dismiss-on-action-label">Dismiss On Action</label>
        </div>
        <br/>

        <div class="mdc-text-field">
          <input type="text" id="message" class="mdc-text-field__input" value="Message deleted">
          <label class="mdc-floating-label" for="message">Message Text</label>
          <div class="mdc-line-ripple"></div>
        </div>
        <br/>

        <div class="mdc-text-field">
          <input type="text" id="action" class="mdc-text-field__input" value="Undo">
          <label class="mdc-floating-label" for="action">Action Text</label>
          <div class="mdc-line-ripple"></div>
        </div>
        <br/>

        <button type="button" class="demo-activate-button mdc-button mdc-button--raised" id="show-snackbar">Show</button>
        <button type="button" class="demo-activate-button mdc-button mdc-button--raised" id="show-rtl-snackbar">Show RTL</button>
        <button type="button" class="demo-activate-button mdc-button mdc-button--raised" id="show-start-aligned-snackbar">Show Start Aligned</button>
        <button type="button" class="demo-activate-button mdc-button mdc-button--raised" id="show-start-aligned-rtl-snackbar">Show Start Aligned (RTL)</button>

        <div id="mdc-js-snackbar"
             class="mdc-snackbar demo-hidden"
             aria-live="assertive"
             aria-atomic="true"
             aria-hidden="true">
          <div class="mdc-snackbar__text"></div>
          <div class="mdc-snackbar__action-wrapper">
            <button type="button" class="mdc-snackbar__action-button"></button>
          </div>
        </div>
        <div dir="rtl">
          <div id="mdc-rtl-js-snackbar"
               class="mdc-snackbar demo-hidden"
               aria-live="assertive"
               aria-atomic="true"
               aria-hidden="true">
            <div class="mdc-snackbar__text"></div>
            <div class="mdc-snackbar__action-wrapper">
              <button type="button" class="mdc-snackbar__action-button"></button>
            </div>
          </div>
        </div>
        <div id="mdc-align-start-js-snackbar"
             class="mdc-snackbar mdc-snackbar--align-start demo-hidden"
             aria-live="assertive"
             aria-atomic="true"
             aria-hidden="true">
          <div class="mdc-snackbar__text"></div>
          <div class="mdc-snackbar__action-wrapper">
            <button type="button" class="mdc-snackbar__action-button"></button>
          </div>
        </div>
        <div dir="rtl">
          <div id="mdc-align-start-rtl-js-snackbar"
               class="mdc-snackbar mdc-snackbar--align-start demo-hidden"
               aria-live="assertive"
               aria-atomic="true"
               aria-hidden="true">
            <div class="mdc-snackbar__text"></div>
            <div class="mdc-snackbar__action-wrapper">
              <button type="button" class="mdc-snackbar__action-button"></button>
            </div>
          </div>
        </div>
      </section>
    </main>

    <script src="/assets/material-components-web.js" async></script>
    <script>
      demoReady(function() {
        var MDCSnackbar = mdc.snackbar.MDCSnackbar;
        var MDCTextField = mdc.textField.MDCTextField;

        var snackbar = new MDCSnackbar(document.getElementById('mdc-js-snackbar'));
        var rtlSnackbar = new MDCSnackbar(document.getElementById('mdc-rtl-js-snackbar'));
        var alignStartSnackbar = new MDCSnackbar(document.getElementById('mdc-align-start-js-snackbar'));
        var alignStartRTLSnackbar = new MDCSnackbar(document.getElementById('mdc-align-start-rtl-js-snackbar'));

        var messageInput = document.getElementById('message');
        var actionInput = document.getElementById('action');
        var multilineInput = document.getElementById('multiline');
        var actionOnBottomInput = document.getElementById('action-on-bottom');
        var actionOnBottomCheckbox = document.getElementById('action-on-bottom-checkbox');
        var dismissOnActionInput = document.getElementById('dismiss-on-action');

        // Since Action on Bottom cannot be checked if Multi-line Input
        // is not, we start with a disabled Action on Bottom option
        actionOnBottomCheckbox.classList.add('mdc-checkbox--disabled');
        actionOnBottomInput.disabled = true;
        actionOnBottomInput.checked = false;

        var show = function(sb) {
          snackbar.dismissesOnAction = dismissOnActionInput.checked;
          var data =  {
            message: messageInput.value,
            actionOnBottom: actionOnBottomInput.checked,
            multiline: multilineInput.checked,
            timeout: 2750
          };

          if (actionInput.value) {
            data.actionText = actionInput.value;
            data.actionHandler = function() {
              console.log(data);
            }
          }

          sb.show(data);
        };

        multilineInput.addEventListener('click', function () {
          if (!multilineInput.checked) {
            actionOnBottomCheckbox.classList.add('mdc-checkbox--disabled');
            actionOnBottomInput.disabled = true;
            actionOnBottomInput.checked = false;
          } else {
            actionOnBottomCheckbox.classList.remove('mdc-checkbox--disabled');
            actionOnBottomInput.disabled = false;
          }
        });

        // Show and hide events demo
        snackbar.listen('MDCSnackbar:show', function () {
          console.log('Received MDCSnackbar:show');
        });

        snackbar.listen('MDCSnackbar:hide', function () {
          console.log('Received MDCSnackbar:hide');
        });

        document.getElementById('show-snackbar').addEventListener('click', function() {
          show(snackbar);
        });

        document.getElementById('show-rtl-snackbar').addEventListener('click', function() {
          show(rtlSnackbar);
        });

        document.getElementById('show-start-aligned-snackbar').addEventListener('click', function() {
          show(alignStartSnackbar);
        });

        document.getElementById('show-start-aligned-rtl-snackbar').addEventListener('click', function() {
          show(alignStartRTLSnackbar);
        });

        [].forEach.call(document.querySelectorAll('.mdc-text-field'), function(tf) {
          MDCTextField.attachTo(tf);
        });

        document.body.classList.remove('loading');
      });
    </script>
  </body>
</html>
